//
//  RadiotableView.m
//  SunXi
//
//  Created by dllo on 15/11/28.
//  Copyright © 2015年 大远. All rights reserved.
//

#import "RadiotableView.h"

@implementation RadiotableView
{
    UITableView *_tableView;
}
- (instancetype)init{
    if (self = [super init]) {
        [self createTable];
    }
    return self;
}
- (void)createTable{
    
    _tableView = [[UITableView alloc]initWithFrame:self.frame style:UITableViewStylePlain];
    [self addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.edges.equalTo(self).with.insets(UIEdgeInsetsMake(0, 0, 64, 0));
        
    }];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.rowHeight = 60;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTable) name:@"更换音乐" object:nil];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [RadioSavemodel shareSingleton].playlistArr.count;
}
- (void)reloadTable{
    [_tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    RadioplaylistCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Radioplaylist"];
    if (!cell){
        cell = [[RadioplaylistCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Radioplaylist"];
    }
    cell.model = [[RadioSavemodel shareSingleton].playlistArr objectAtIndex:indexPath.row];
    if ([RadioSavemodel shareSingleton].playNumber == indexPath.row) {
        cell.now = YES;
    }else{
        cell.now = NO;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [_tableView deselectRowAtIndexPath:indexPath animated:YES];
    [RadioSavemodel shareSingleton].playNumber = indexPath.row;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"更换音乐" object:nil];

}




@end
